package com.trust.pams.service.read.impl;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.chasonx.common.model.PageResult;
import com.chasonx.common.util.Ret;
import com.trust.pams.dao.mapper.PamsUserMapper;
import com.trust.pams.domain.PamsUser;
import com.trust.pams.model.query.PamsUserQuery;
import com.trust.pams.service.read.PamsQuoteRead;
import com.trust.pams.service.read.PamsUserRead;
import com.trust.pams.util.DataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
@Service
public class PamsUserReadImpl implements PamsUserRead {

    private static final Logger log = LoggerFactory.getLogger(PamsQuoteReadImpl.class);

    @Autowired
    PamsUserMapper pamsUserMapper;

    @Override
    public Ret ListPamsUser(PamsUserQuery userQuery) {
        PageResult<PamsUser> userQueryPageResult =  new PageResult<PamsUser>();
        HashMap<String, Object> map = new HashMap<String, Object>();
        if(DataUtil.isNotEmpty(userQuery.getName())){
            map.put("name",userQuery.getName());
        }else{
            map.put("name",userQuery.getName());
            map.put("pageSize",userQuery.getPageSize());
            map.put("nextPage",userQuery.getPageNumber());
        }
        List<PamsUser> pamsUserList= pamsUserMapper.queryPamsUser(map);
        Integer count = pamsUserMapper.queryPamsUserCount(map);
        userQueryPageResult.setTotalRow(count);
        userQueryPageResult.setData(pamsUserList);
        return Ret.get().setData(userQueryPageResult).success();
    }
}
